<!--Generate by Kevin's CodeBuilder -->
<!--请注意！这里是页面片段，定义的标签ID，js变量不要与index.html列表页面重复-->
<!--如果是较复杂的页面，可以修改window的数据类型(dataType: iframe),然后将form.html改为完整的页面,实现iframe隔离，需要修改curdObj的访问方式为parent.curdObj-->
<div id="form_container" class="form_container">
		<!--利用隐藏的id标签区分是新增/编辑-->
		<input type="hidden" id="id" name="id" th:value="*{id}"/>
		<input type="hidden" id="old_userAccount" name="old_userAccount" value=""/>
		
		<table class="form_table" style="margin-top:20px">
				<tr>
					<td class="label label30">[(${Lang.user_orgName})]</td>
					<td><input id="orgId" name="orgId" class="form_input form_input50" type="text"/></td>
				</tr>
				<tr>
					<td class="label label30">[(${Lang.user_userAccount})]</td>
					<td><input id="userAccount" name="userAccount" class="form_input form_input50" type="text"/></td>
				</tr>
				<tr id="pwd_tr">
					<td class="label label30">[(${Lang.user_userPwd})]</td>
					<td><input id="userPwd" name="userPwd" class="form_input form_input50" type="password"/></td>
				</tr>
				<tr>
					<td class="label label30">[(${Lang.user_userName})]</td>
					<td><input id="userName" name="userName" class="form_input form_input50" type="text"/></td>
				</tr>				
				<tr>
					<td class="label label30">[(${Lang.user_userStatus})]</td>
					<td>					
						<label class="k_radio_label k_radio_anim">
                            <input type="radio" name="userStatus" checked="checked" value="1" /><i class="k_radio_i"></i>[(${Lang.common_yes})]
                        </label>
                        <label class="k_radio_label k_radio_anim">
                            <input type="radio" name="userStatus" value="0" /><i class="k_radio_i"></i>[(${Lang.common_no})]
                        </label>
					</td>
				</tr>			
				<tr>
					<td class="button_td" colspan="2">
						<button id="button_submit" class="common_button"><i class="fa fa-floppy"></i>[(${Lang.common_save})]</button>
						<button id="button_goback"  class="common_button"><i class="fa fa-reply-all"></i>[(${Lang.common_goback})]</button>
					</td>
				</tr>
		</table>
</div>
<script type="application/javascript" th:inline="javascript">
		var $form,
			entityJson,
			vm,
			comBox,
			idValue;//用于区分新增,编辑
		$(function(){			
			$form = $("#form_container");
			var orgJson = [(${orgJson})];
			var opts = {
		        data: orgJson,//数据 参考树数据
	            default: {
	                "id": '',
	                "text": "[(${Lang.common_pleaseSelected})]"
	            },
	            placeholder: "[(${Lang.common_pleaseSelected})]", //默认选择项目
	            checkox:false,
	            mutilChecked:false,
	            url: $B.getHttpHost(ctxPath) + "org/query",	          
	            checkfather: true, // 单选的时候，是否可以选择父节点
	            readonly: true, //不可以编辑                
	            plainStyle: true, //\"true\" 为简单无图标样式
	            textField: 'text', //菜单名称字段，默认为text
	            idField: 'id', //菜单id字段,默认为id
	        };	        	       
	        		
			idValue = $form.find("#id").val();
			/**创建mvvm表单，将实体json绑定到表单**/
			if(idValue === ""){
				entityJson = $B.parseForm($form);
			}else{
				$("#pwd_tr").hide();
				entityJson = [(${entityJson})];				
				opts.default = {id:entityJson.orgId,text:entityJson.extFeildsMap.orgName};
			}
			comBox = new $B.Combox($("#orgId"), opts);
			/***将实体数据绑定为mvvm表单***/
			vm = $B.bindForm($form, entityJson);
			
			//创建校验
			var validObj = new $B.Validate({
					orgId: [{rule:'require'}],
					userAccount: [{rule:'require'},{rule :{ minlength:2 }}],
					userPwd: [{rule:'require'},{rule :{ minlength:6 }}],
					userName: [{rule:'require'},{rule :{ minlength:2 }}]
            }, $form);
			
			/**绑定事件**/
			$form.find("#button_goback").click(function(){
				curdObj.closeWindow();
			});
			$form.find("#button_submit").submit(function(){
				var isPast = validObj.valid();				
				if(isPast){
					//提交表单数据
					if(idValue === ""){
						curdObj.add(vm.getJson());
					}else{
						curdObj.update(vm.getJson());
					}
				}				
			});
		});
</script>
